<script>
    function changeUsername(){
        //alert("hh");
        var newData=$("#User_username").attr("value");
        var oldData='<?php echo Yii::app()->user->name;?>';
        if(oldData!=newData){
            $( "#dialog-confirm" ).dialog({
                    resizable: false,
                    height:200,
                    modal: true,
                    buttons: {
                        "Ok": function() {
                            $( this ).dialog( "close" );
                            $('#user-form').submit();
                        },
                        Cancel: function() {
                            $("#User_username").attr("value",oldData);
                            $( this ).dialog( "close" );
                        }
                    }
                });
        }
    }
</script>
<?php
$this->pageTitle = Yii::app()->name . ' - ' .
        Yii::t("UserModule.user", "Profile");

$this->breadcrumbs = array(
    Yii::t("UserModule.user", "Profile") => array('myprofile'),
    Yii::t("UserModule.user", "Edit"),
);
?><h2><?php echo Yii::t("UserModule.user", 'Edit profile'); ?></h2>

<?php
$this->menu = array(
    array(
        'label' => Yii::t('UserModule.user', 'Manage User'),
        'url' => array('admin'),
        'visible' => Yii::app()->user->isAdmin()
    ),
    array(
        'label' => Yii::t('UserModule.user', 'Manage Roles'),
        'url' => array('role/role/admin'),
        'visible' => Yii::app()->user->isAdmin() &&
        $this->module->hasModule('role')
    ),
    array(
        'label' => Yii::t('UserModule.user', 'List User'),
        'url' => array('list'),
        'visible' => !Yii::app()->user->isAdmin()
    ),
    array(
        'label' => Yii::t('UserModule.user', 'Back to Profile'),
        'url' => array('myprofile')
    ),
    array(
        'label' => Yii::t('UserModule.user', 'Change password'),
        'url' => array('changepassword')
    ),
    array(
        'label' => Yii::t('UserModule.user', 'Logout'),
        'url' => array('logout'))
);
?>

<?php if (Yii::app()->user->hasFlash('profileMessage')): ?>
    <div class="success">
        <?php echo Yii::app()->user->getFlash('profileMessage'); ?>
    </div>
<?php endif; ?>
<div class="form">

    <?php echo CHtml::beginForm('','POST',array('id'=>'user-form')); ?>

    <p class="note">
        <?php echo Yii::t("UserModule.user", 'Fields with <span class="required">*</span> are required.'); ?></p>

    <?php
    echo CHtml::errorSummary($model);
   ?>

    
    <div class="row">
        <?php echo CHtml::activeLabelEx($model, 'username'); ?>
        <?php echo CHtml::activeTextField($model, 'username', array('size' => 30, 'maxlength' => 50)); ?>
        <?php echo CHtml::error($model, 'username'); ?>
    </div>
    <div class="row">
        <?php echo CHtml::activeLabelEx($model, 'password'); ?>
        <?php echo CHtml::activePasswordField($model, 'password', array('size' => 30, 'maxlength' => 128)); ?>
        <?php echo CHtml::error($model, 'password'); ?>
    </div>
    

    <div class="row buttons">
        <?php echo CHtml::button($model->isNewRecord ? Yii::t("UserModule.user", 'Create') : Yii::t("UserModule.user", 'Save'),array('onClick'=>'changeUsername();')); ?>
    </div>

    <?php echo CHtml::endForm(); ?>

</div><!-- form -->
<div id="dialog-confirm" style="display: none;">
        <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Your user credentials are changing. You will be automatically logged out and will need to login again.</p>
    </div>
